<template>
	<view>
		<view>
			<view style="margin-top: 10rpx;background-color:#fee2cc;margin-left: -30rpx;margin-right: 300rpx;height: 60rpx;width: 250rpx;">
						  <text style="padding-left: 70rpx;padding-top: 10rpx;position: absolute;">校园卡认证</text>
						  </view>
				  <u-form>
			  			<u-form-item label="姓名" label-width="140rpx" style="width: 88%;margin: 0 auto;"  >
			  				<u-input v-model="form.name" shape="circle" />
			  			</u-form-item>
			  			<u-form-item label="学号" label-width="140rpx" style="width: 88%;margin: 0 auto;">
			  				<u-input v-model="form.number" shape="circle"/>
			  			</u-form-item>
						<u-form-item label="校园卡正面" label-width="140rpx" style="width: 88%;margin: 0 auto;">
							<block >
								<u-upload ref="uUpload" :size-type="['original', 'compressed']" name="files" :max-count="1"  upload-text="上传大学面"
									:action="uploadImgUrl" @on-uploaded="submit1" :auto-upload="false" height="300rpx" width="300rpx"></u-upload>
							
									
							</block> 
						</u-form-item>
						</u-form-item>
						<u-form-item label="校园卡反面" label-width="140rpx" style="width: 88%;margin: 0 auto;">
							<block >
								<u-upload ref="uUpload1" :size-type="['original', 'compressed']" name="files" :max-count="1"  upload-text="上传信息面"
									:action="uploadImgUrl" @on-uploaded="submit2" :auto-upload="false" height="300rpx" width="300rpx"></u-upload>
							
									
							</block> 
						</u-form-item>
		
				 </u-form>
				 
				 <u-button style="margin-top: 30rpx;background-color:#fee2cc;width: 90%;border-radius: 30rpx;" @click="arrestation">认证</u-button>
		</view>
	</view>
</template>

<script>
	export default {
		onLoad() {
			let userinfo=uni.getStorageSync("userInfo")
			this.form.userid=userinfo.id
		},
		data() {
			return {
				form:{
					name:'',
					number:'',
					media1:'',
					media2:'',
					userid:''
				},
				uploadImgUrl: this.$c.domain + 'oss/upmutiload',
			};
		},
		methods:{
			arrestation(){
				if (!this.form.name) {
					this.$u.toast('姓名不能为空');
					return;
				}
				if (!this.form.number) {
					this.$u.toast('学号不能为空');
					return;
				}
				this.$refs.uUpload.upload();
				this.$refs.uUpload1.upload();
				},
			submit1(e) {
				uni.showLoading({
					mask: true,
					title: '提交中'
				});
			    
				let mediaList = [];
				
				e.forEach(function(item, index) {
					
					mediaList.push(String(item.response.url));
					
				});
			
				this.form.media1 = mediaList.toString();
				if(this.form.media1==" "){
					this.$u.toast('请选择图片');
					return;
				}
			   // 传递帖子表单到后端的接口
				
				uni.hideLoading();
				// setTimeout(uni.switchTab({
				// 	url: '/pages/partner/index'
				// }), 1500);
			},
			submit2(e) {
				uni.showLoading({
					mask: true,
					title: '提交中'
				});
			    
				let mediaList = [];
				
				e.forEach(function(item, index) {
					
					mediaList.push(String(item.response.url));
					
				});
			
				this.form.media2 = mediaList.toString();
				if(this.form.media2==" "){
					this.$u.toast('请选择图片');
					return;
				}
			   // 传递帖子表单到后端的接口
				
				uni.hideLoading();
				
			
			this.$H.post('information/add', this.form).then(res => {
				
				if(res.code == 200){
				uni.showToast({
					icon: "none",
					title: '发布成功，等待管理员审核',
					
				})
				
				setTimeout(function () {
				                        uni.reLaunch({
				                        	url:'/pages/mine/index'
				                        })
				                    }, 2000);
				
				}else{
				uni.showToast({
					icon: "none",
					title: '提交失败，请重新操作'
				})
				}
			
			
				
			});
			},
			}
		
	}
</script>

<style lang="scss">

</style>
